#include <pthread.h>
#include <iostream>
#include <unistd.h>
using namespace std;

void *threadRoutine(void *args)
{
  pthread_detach(pthread_self());
  for (int i = 0; i < 20; i++)
  {
    cout << "[" << pthread_self() << "] pthread " << (long int)args << " is running..." << endl;
    sleep(1);
  }
  return nullptr;
}
int main()
{
  pthread_t tp[3];
  for (int i = 0; i < 3; i++)
  {
    pthread_create(&tp[i], nullptr, threadRoutine, (void *)i);
  }
  while (1)
  {
    cout << "main thread is running!" << endl;
    sleep(1);
  }
  return 0;
}
